﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using XCI.Extensions;
using XCI.Sys.Service;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    public partial class FrmModifyPassword : FrmBase
    {
        public FrmModifyPassword()
        {
            InitializeComponent();
            WinHelper.BindEnterToTab(this, null);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string oldPwd = editOldPwd.Text;
            string newPwd = editNewPwd.Text;
            string confirmPwd = editComfirmPwd.Text;

            if (oldPwd.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入原密码");
                editOldPwd.Select();
                return;
            }

            if (newPwd.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入新密码");
                editNewPwd.Select();
                return;
            }

            if (!newPwd.Equals(confirmPwd))
            {
                MessageBoxHelper.ShowWarn("两次密码输入不一致请重新输入");
                editComfirmPwd.Select();
                return;
            }

            var result = UserService.Instance.ModifyPassword(SysRuntime.CurrentUser.Id, oldPwd, newPwd);
            if (result)
            {
                MessageBoxHelper.ShowMessage("密码修改成功");
                this.Close();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}